package com.yanqu.road.server.cmd.activity.flowerstudy.fromcross;

import com.yanqu.road.entity.activity.ActivityRewardResult;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.flowerstudy.FlowerStudyModule;
import com.yanqu.road.server.pb.ActivityPb;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = GameProtocol.S_FLOWER_STUDY_CROSS_GET_RANK_REWARD, desc = "获取花城书房跨服排行榜奖励")
public class FlowerStudyGetRankRewardFromCrossCmd extends AbstractCommand {
    private int activityId;
    private int conditionId;
    private int myRank;
    private ActivityRewardResult rewardResult;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossActivityGetRewardRespMsg reqMsg = CrossActivityProto.CrossActivityGetRewardRespMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionId = reqMsg.getConditionId();
        myRank = reqMsg.getRank();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        rewardResult = player.getModule(FlowerStudyModule.class).dealNewCrossRankActivityReward(activityId, conditionId, myRank);
    }

    @Override
    public void sendData(GamePlayer player) {
        rewardResult.setActivityId(activityId);
        rewardResult.setConditionId(conditionId);
        ActivityProto.ActivityGetRewardRespMsg.Builder respMsg = ActivityPb.parseActivityGetRewardRespMsg(rewardResult);
        if(null != respMsg) {
            player.sendPacket(Protocol.U_FLOWER_STUDY_GET_RANK_REWARD, respMsg);
        }
    }
}
